﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using AimGameEngine.EditorObject;

using AimGameLibrary;
using AimGameLibrary.GameObject;

namespace AimGameEngine.NodeEditorObject
{
    public class NodeScreen : NodeBaseControl
    {
        protected String MyNodeDraw = "NULL";
        protected String MyNodeUpdate = "NULL";
        protected String MyNodeCamera = "NULL";
        protected Boolean StartHere = false;
        public Boolean StartherE { get { return StartHere; } set { StartHere = value; } }
        public Double FaceIn = 0.5;
        public Double FaceOut = 0.5;

        //public Dictionary<String, NodeObject> DictionaryObject;
        NodeDraw Nodedraw;
        NodeUpdate Nodeupdate;

        public NodeDraw NodedrW { get { return Nodedraw; } }
        public NodeUpdate NodeupdatE { get { return Nodeupdate; } }
        public String NodeCamerA { get { return MyNodeCamera; } }
        
        public NodeScreen(SpriteBatch inputspritebatch, Camera inputcamera, NodeData inputData
            , List<IDraw> MyListDraw, List<IUpdateMainTime> MyListUpdateTime, Dictionary<String, NodeObject> MyListObject, Dictionary<String, NodeObject> MyListType)
            : base(inputspritebatch, inputcamera, inputData, MyListDraw,MyListUpdateTime, MyListObject, MyListType)
        {
            if (MyListType.Count == 0)
                StartHere = true;

            //DictionaryObject = new Dictionary<string,NodeObject>();

            Connecter intputDraw = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Draw, this);
            ListConnectpoint.Add(intputDraw);

            Connecter inputUpdate = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Update, this);
            ListConnectpoint.Add(inputUpdate);

            Connecter inputCamera = new Connecter(inputspritebatch, inputcamera, Syco.Input, NodeTypeValue.Camera, this);
            ListConnectpoint.Add(inputCamera);
        }

        public override void SetupInput(Connecter Thisconnect, Connecter connectOutput)
        {
            if (connectOutput.MyNode.GetType() == typeof(NodeDraw))
            {
                MyNodeDraw = connectOutput.MyNode.MyData.MyName;
                Nodedraw = (NodeDraw)connectOutput.MyNode;
            }
            else if (connectOutput.MyNode.GetType() == typeof(NodeUpdate))
            {
                MyNodeUpdate = connectOutput.MyNode.MyData.MyName;
                Nodeupdate = (NodeUpdate)connectOutput.MyNode;
            }
            else if (connectOutput.MyNode.GetType() == typeof(NodeCamera))
            {
                MyNodeCamera = connectOutput.MyNode.MyData.MyName;
            }
        }

        public override void ClearInput(Connecter ThisInputConnect, Connecter ThisConnectClear, string NameThisClear)
        {
            //base.ClearInput(ThisConnectClear, NameThisClear);
            switch (ThisConnectClear.MyType)
            {
                case NodeTypeValue.Draw:
                    MyNodeDraw = "NULL";
                    Nodedraw = null;
                    break;
                case NodeTypeValue.Update:
                    MyNodeUpdate = "NULL";
                    Nodeupdate = null;
                    break;
                case NodeTypeValue.Camera:
                    MyNodeCamera = "NULL";
                    break;
            }
        }

        public override void ShowProprety(ArrayList Temp, CallBack input)
        {
            base.ShowProprety(Temp, input);
            PropretyScreen propretyscreen = new PropretyScreen(this);
            //propretyscreen.Deactivate += new EventHandler(input.Deactivate);
            propretyscreen.okButton.Click += new EventHandler(input.Deactivate);
            propretyscreen.ShowDialog();
            
        }

        protected override void SubDraw()
        {
            base.SubDraw();
            #region Draw Strte here
            if (Font != null && StartHere)
                this.spritebatch.DrawString(
                    this.Font
                    , "Start Here"
                    , this.camera.ApplyPosition(this) + new Vector2(20, 20)
                    , Color.Black
                    , MyViewData.Rotation
                    , MyViewData.Origin
                    , MyViewData.Scale
                    , MyViewData.Spriteeffects
                    , this.FontDepth);
            #endregion
        }

        public void Restete()
        { 
            foreach(String keys in this.MyDictionaryType.Keys)
            {
                if(this.MyDictionaryType[keys].GetType() == typeof(NodeScreen))
                {
                NodeScreen screen = (NodeScreen)this.MyDictionaryType[keys];
                screen.StartHere = false;
                }
            }
        }

        public override void SaveData(System.Collections.ArrayList Thislist, SaveMode inputsavemode)
        {
            base.SaveData(Thislist,inputsavemode);

            Thislist.Add(StartherE);
            Thislist.Add(FaceIn);
            Thislist.Add(FaceOut);

            Thislist.Add(MyNodeCamera);
        }

        public override void LoadData(Identification getdata, int IndexData)
        {
            base.LoadData(getdata, IndexData);

            if (getdata.Items.GetValue(IndexData + 1).GetType() == typeof(NodeInputMode))
            StartherE = (Boolean)getdata.Items.GetValue(IndexData + 1);

            if (getdata.Items.GetValue(IndexData + 2).GetType() == typeof(Double))
            FaceIn = (Double)getdata.Items.GetValue(IndexData + 2);

            if (getdata.Items.GetValue(IndexData + 3).GetType() == typeof(Double))
            FaceOut = (Double)getdata.Items.GetValue(IndexData + 3);
        }
    }
}
